<template>
	<view>
		<view class="demo-nav2" style="width: 100%; margin-top: 28rpx;">
			<gui-switch-navigation :items="switch_navigation" @change="navchange2" textAlign="center" :isCenter="true"
				activeDirection="center" :size="0" activeLineBg="linear-gradient(to right, #ede844, #ede844)"
				activeColor="#fff" :margin="20" padding="30rpx" activeLineHeight="8rpx" lineHeight="40rpx"
				activeLineWidth="200rpx"></gui-switch-navigation>
		</view>

		<view class="gui-margin-top gui-bg-gray search-warp gui-border-box">
			<gui-search @inputting="inputting" @confirm="confirm" :clearBtn="false"></gui-search>
			<!-- 关闭清除按钮示例 -->
			<!-- gui-search @inputting="inputting" @confirm="confirm" :clearBtn="false"></gui-search -->
		</view>

		<view class="gui-margin-top">
			<gui-article-list :articles="show_data" @newstap="newstap"></gui-article-list>
		</view>

		<view v-if="no_more" class="gui-color-gray gui-text-center" style="margin: 20rpx auto;width: 480rpx;">
			<text>无更多数据</text>
		</view>
		
	</view>
</template>
<script>
	export default {
		data() {
			return {
				user: [],
				cate: [],
				switch_navigation: [{
					id: 0,
					name: '全部'
				}],
				pages: 0,
				a_id: 0,
				switch_index: 0,
				no_more: false,
				show_data: [],
				search: ''
			}
		},
		onLoad: function(option) {
			this.user = uni.getStorageSync("member");
			// console.log(this.user);
		},
		onReady() {
				uni.showLoading({
					title: '加载中'
				});
			this.get_hzj_cate();
		},
		methods: {
			newstap(e) {
				// 获取新闻 id
				var newsId = e;
				console.log(newsId);
				uni.navigateTo({
					url: './publicity_detail?id=' + e
				});
			},
			navchange2(index) {
				this.switch_index = index;
				this.pages = 0;
				if (index) {
					this.a_id = this.cate[index - 1].id;
				} else {
					this.a_id = index;
				}
				this.get_policy();
			},
			get_hzj_cate() {
				let self = this;
				uni.showLoading({
					title: '加载中...'
				});
				let url = '/hzj_apply/get_category'
				let parm = {
					c_id: 0
				}
				self.$boya.NPost(url, parm, function(res) {
					if (res.code == 200) {
						self.cate = res.data;
						for (let i = 0; i < res.data.length; i++) {
							if ('c_res: ', res.data[i].id != 74) {
								self.switch_navigation.push({
									'id': i + 1,
									'name': res.data[i].name
								});
							}
						}
						self.get_policy();
						// console.log(c_res,'cate');
					} else {
						uni.showModal({
							title: '提示',
							content: res.data
						});
					}
					uni.hideLoading();
				})
			},
			get_policy(nofirst) {
				if (!nofirst) {
					uni.showLoading({
						title: '加载中...'
					});
				}
				let self = this;
				console.log('self.a_id: ', self.a_id);
				let url = '/hzj_apply/get_policy'
				let parm = {
					pages: self.pages,
					user_id: self.user.id,
					a_id: self.a_id,
					search: self.search
				}
				self.$boya.NPost(url, parm, function(res) {
					console.log('res: ', res);
					if (nofirst) { //区分不是第一次
						for (var i = 0; i < res.data.length; i++) {
							res.data[i].imgs = JSON.parse(res.data[i].thumb);
							self.show_data.push(res.data[i]);
						}
						uni.hideLoading();
						console.log(self.show_data, 'new');
					} else {
						for (let i = 0; i < res.data.length; i++) {
							res.data[i].imgs = JSON.parse(res.data[i].thumb);
						}
						self.show_data = res.data;
						console.log(self.show_data, 'news');
						uni.hideLoading();
					}
					if (res.data.length == 0) {
						self.no_more = true;
					}
				})
			},
			reload() {
				let self = this;
				if (this.no_more) {
					console.log("无更多数据");
				} else {
					self.pages++;
					console.log('加载更多');
					self.get_policy(true);
				}
			},
			// 监听输入
			inputting: function(e) {
				console.log(e);
				this.search = e;
			},
			// 监听提交
			confirm: function(e) {
				console.log(e);
				this.get_policy();
			}
		}
	}
</script>
<style>
	.search-warp {
		width: 750rpx;
		padding: 15rpx 50rpx;
	}

	.gui-card-view {
		background-color: #FFFFFF;
		padding: 25rpx;
	}

	.gui-card-body {
		padding-bottom: 25rpx;
	}

	.gui-card-img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 80rpx;
	}

	.gui-card-desc {
		width: 400rpx;
		margin-left: 25rpx;
		flex: 1;
	}

	.gui-card-name {
		font-size: 28rpx;
		color: #333333;
		line-height: 40rpx;
		margin-right: 20rpx;
	}

	.gui-card-text {
		line-height: 40rpx;
		font-size: 24rpx;
		color: #888888;
	}

	.gui-card-footer {
		margin-top: 25rpx;
	}

	.gui-card-footer-item {
		width: 100rpx;
		text-align: center;
		flex: 1;
		line-height: 38rpx;
		font-size: 26rpx;
		color: #666666;
	}
</style>